﻿using Cemit.PolyProto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cemit.NetFramework
{
    class GameClient : PolyClient
    {
        public bool IsLogined { get; private set; } = false;

        [System.Obsolete("直接使用InstancesFrameSyncRoom(int)生成FrameSyncRoom实例")]
        private OperationFrameBuffer frameBuffer;
        
        public async Task<LoginResult> Login(string name)
        {
            var result = await socket.Login(name);
            IsLogined = result == LoginResult.Successful;
            return result;
        }

        /// <summary>创建FrameSyncRoom实例</summary>
        public FrameSyncRoom InstancesFrameSyncRoom(int roomId)
        {
            return new FrameSyncRoom(roomId, socket);
        }

        /// <summary>初始化帧缓冲，开始接收帧缓冲消息</summary>
        [System.Obsolete("直接使用InstancesFrameSyncRoom(int)生成FrameSyncRoom实例")]
        public OperationFrameBuffer InstanceOperationFrameBuffer()
        {
            frameBuffer = new OperationFrameBuffer();

            socket.AddMessageListener<F>(
                frame => frameBuffer.AddFrame((F)frame));

            return frameBuffer;
        }

        [System.Obsolete("直接使用InstancesFrameSyncRoom(int)生成FrameSyncRoom实例")]
        public void SendOperation(O operation)
        {
            socket.Send(operation);
        }
    }
}
